package com.xinghai.system.mapper;

import java.util.List;
import com.xinghai.system.domain.QdOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinghai.system.domain.QdPayOrderInfo;
import com.xinghai.system.domain.vo.QdPayOrderVo;
import org.apache.ibatis.annotations.Select;

/**
 * 订单模块Mapper接口
 *
 * @author xinghai
 * @date 2024-12-04
 */
public interface QdOrderMapper  extends BaseMapper<QdOrder>
{

    @Select("select a.id userId,a.ascription_store storeId,a.bank_info bankInfo,a.bank_no bankNo," +
            "a.bank_name bankName,a.store_name storeName,a.nick_name userName,a.user_phone userPhone," +
            "ifnull(b.amount,0) buyAmount,ifnull(b.num,0) buyNum," +
            "ifnull(c.amount,0) sellAmount,ifnull(c.num,0) sellNum from qd_user a " +
            "LEFT JOIN (select buyer_user_id,sum(price) amount,count(1) num from qd_order " +
            "where DATE_FORMAT(deal_time,\"%Y-%m-%d\") = DATE_FORMAT(now(),\"%Y-%m-%d\") and `status` = 0 " +
            "GROUP BY buyer_user_id) b on a.id=b.buyer_user_id " +
            "LEFT JOIN (select seller_user_id,sum(price) amount,count(1) num from qd_order " +
            "where DATE_FORMAT(deal_time,\"%Y-%m-%d\") = DATE_FORMAT(now(),\"%Y-%m-%d\") and `status` = 0 " +
            "GROUP BY seller_user_id) c on a.id=c.seller_user_id " +
            "where a.ascription_store = #{storeId}")
    List<QdPayOrderInfo> getMemberDealData(Long storeId);
}
